package icrts.logic;

import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPopupMenu;

// builds a sample ranged unit with 20 hp, 1 armor, 1 dmg
// no bonus, at position (2,3), with a display char of R 
// and a range of 2
public class SampleRangedUnit extends AbstractRangedUnit{
	
	Color SampleRangedUnitColor = Color.RED; 
	int SampleRangedUnitSize = 10;
  
	public SampleRangedUnit (Position p){
		super(20, 1, 3, null,p, 2);
     this.identifier = "SampleRangedUnit at " + p.printPos();
	}


	public void draw(Graphics g, boolean selected){

		g.setColor(SampleRangedUnitColor);

		int posX = this.getPos().getX();
		int posY = this.getPos().getY();

		g.fillOval(posX, posY, SampleRangedUnitSize, SampleRangedUnitSize);

        if ( selected ){
               g.setColor(Color.GREEN);
               g.drawOval(posX,posY,SampleRangedUnitSize, SampleRangedUnitSize);
        }
	}

	protected Position findClosestFreeArea(int x, int y){
		return new Position(x,y);
	}


	// checks if the given "belongs" to / selects the game object
	public boolean selects(int x, int y){

        int posX = this.getPos().getX();
		int posY = this.getPos().getY();
        
		double distance = (double)Math.sqrt( (posX - x) * ( posX - x) +
                                ( posY - y ) * ( posY - y) );
                
		if ( distance <= SampleRangedUnitSize )
                   return true;

		return false;
	}

	// obtains the specific JPopupMenu of this object
	public JPopupMenu getJPopupMenu(){	
		return new JPopupMenu();		
	}

        public void moveThis(int finalX, int finalY, int time) {
            int initialX = this.getPos().getX();
            int initialY = this.getPos().getY();
            int diffX    = (finalX - initialX)/time;
            int diffY    = (finalY - initialY)/time;

        }

}
